﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess.Classes;
using DataAccess;
using Webmau.Controls;


namespace Webmau
{
    public partial class ChiTietPhongTro : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PopulateControls();
            }

        }
        private void PopulateControls()
        {
            string id = Request.QueryString["IDPhongTro"];
            PhongTro1 data = PhongTro1.Single(id);
            if (data != null)
            {
                lblTen.Text = data.Ten;
                lblThongTin.Text = HttpUtility.HtmlEncode(data.ThongTin);
                lblGia.Text = data.GiaTien.ToString("0,000") + " VNĐ";
                imgHinh.ImageUrl = Link.ToHinhDanhSachDiaDiem(data.HinhDaiDien);
                lnkDatPhong.NavigateUrl = Link.ToDatPhong(id);
            }
        }
        protected void btnBinhLuan_Click(object sender, EventArgs e)
        {
            if (Session["id"] == null)
            {
                Response.Redirect("DangNhap.aspx");
            }
            else
            {
                if (Session["id"] != null)
                {
                    DataAccess.Classes.BinhLuan bl = new DataAccess.Classes.BinhLuan();
                    bl.IDPhongTro = Convert.ToInt32(Request.QueryString["IDPhongTro"].ToString());
                    bl.IDNguoiDung = Session["id"].ToString();
                    bl.NoiDung = txtNoidung.Text;
                    bl.Ngay = Convert.ToDateTime(DateTime.Now.ToShortDateString().ToString());
                    DataAccess.Classes.BinhLuan.Them(bl);
                    Response.Redirect("ChiTietPhongTro.aspx" + "?IDPhongTro=" + Request.QueryString["IDPhongTro"].ToString());

                }
            }
        }
    }
}
